import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const AdminInfoKey = 'Admin-Info'
const isShopManageKey = 'isShopManage'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function setIsShopManage(isShopManage) {
  const info = Cookies.get(AdminInfoKey)
}

export function getIsShopManage(isShopManage) {
  return Cookies.get(isShopManageKey) == 'true'
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function setAdminInfo(admin) {
  const ret = Cookies.set(AdminInfoKey, JSON.stringify(admin))
  localStorage.setItem(AdminInfoKey, JSON.stringify(admin))
  console.log('setAdminInfo:' + ret)
  return ret
}

export function getAdminInfo() {
  const info = Cookies.get(AdminInfoKey) || localStorage.getItem(AdminInfoKey)
  if (info && info.trim() != '') {
    return JSON.parse(info)
  }
  return {}
}
